#include <stdio.h>
#include <string.h>
void test01()
{
    char str1[] = {'h', 'e', 'l', 'l', 'o'};
    printf("%s\n", str1);

    char str2[100] = {'h', 'e', 'l', 'l', 'o'};
    printf("%s\n", str2);
}

//1.字符串拷贝
void copyString01(char* dst, const char* source)
{
    int len = strlen(source);
    for (size_t i = 0; i < len; ++i){
        dst[i] = source[i];
    }
    dst[len] = '\0';
}
void copyString02(char* dst, const char* source)
{
    // while (*source != '\0'){ //可以省略
    while (*source){
        *dst = *source;
        ++dst;
        ++source;
    }
    *dst = '\0';
}
void copyString03(char* dst, const char* source)
{
    while(*dst++ = *source++);
}
void test02()
{
    char* source = "hello world";
    char buf[1024] = {0};
    //copyString01(buf, source);
    //copyString02(buf, source);
    copyString03(buf, source);
    printf("%s\n", buf);
}

//字符串反转
void reverseString01(char* str)
{
    if(NULL == str){
        return;
    }

    int len = strlen(str);

    int start = 0;
    int end = len -1;
    while (start < end){
        char temp = str[start];
        str[start] = str[end];
        str[end] = temp;
        ++start;
        --end;
    }
}
void reverseString02(char* str)
{
    if(NULL == str){
        return;
    }

    int len = strlen(str);

    char* pStart = str;
    char* pEnd = str+len-1;

    while (pStart < pEnd){
        char temp = *pStart;
        *pStart = *pEnd;
        *pEnd = *pStart;

        ++pStart;
        --pEnd;
    }
}
void test03()
{
    char p[] = "abcdefghijklmnopq";
    // reverseString01(p);
    reverseString02(p);
    printf("%s\n", p);
}
int main(int argc, char const *argv[])
{
    //test01();
    // test02();
    test03();
    return 0;
}
